<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>主菜单</title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<script src="js/mui.min.js"></script>
		<script src="js/addressinitialization.js"></script>
		<link rel="stylesheet" href="css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="css/font-awesome.css" />
		<link rel="stylesheet" type="text/css" href="css/startinventory.css" />
		<script type="text/javascript">
			mui.init();
			window.onload = function() {
				search_store(); //获取存放地
				start(); //开始扫描
				again(); //继续扫描
				complete_but(); //完成扫描
			}
			// 预加载详情页
			mui.plusReady(function() {
				mui.preload({
					url: 'complete_sub.html',
					id: 'complete_sub.html'
				});
				sub_page = plus.webview.getWebviewById('complete_sub.html');
			})

			//获取存放地
			function search_store() {
				var selections = document.getElementById("storage_goodsAddr");
				mui.ajax(IP + '/ias/AndroidInputAsset/listDepartStore', {
					type: "GET",
					dataType: 'json',
					success: function(response) {
						var store = response.data;
						if(store == "空") {
							mui.confirm('数据错误，请检查登陆状态', '提示', "是", function(e) {
								if(e.index == 0) {
									window.location = "mainPage.html";
								} else {; //
								}
							});
						} else {
							for(var i = 0; i < store.length; i++) {
								option = document.createElement("option");
								option.value = store[i];
								option.text = store[i];
								selections.options.add(option);
							}
						}
					},
					error: function(xhr, textStatus, errorThrown) {
						mui.alert("数据错误，请检查登陆状态");
					}
				})
			}

			// 监听跳转详情页
			function tap_sub_event() {
				mui(".mui-table-view-cell").on('tap', '.m-numbers-href', function() {
					var title = this.getAttribute("title");
					var id = this.getAttribute("id");
					mui.fire(sub_page, 'get_detail', {
						title_: title,
						id_: id
					});
				})
			}

			//开始扫描
			function start() {
				document.getElementById("start_close").addEventListener("click", function() {
					//获取

					//mui.toast("开始扫描");
					//将扫描存放地存入域中
					var storeName = mui("#storage_goodsAddr")[0].value;
					mui.ajax(IP + '/ias/AndroidInputAsset/setStoreName', {
						data: {
							storeName: storeName
						},
						type: 'post',
						dataType: 'json',
						timeout: 10000,
						headers: {
							'Content-Type': 'application/json'
						},
						success: function(data) {
							if(data.result == "error") {
								if(data.msg == "开始盘点") {
									mui.toast(data.msg);
								} else {
									mui.alert(data.msg);
									document.getElementById("start_close").innerText = "开始扫描";
								}
							} else {;
							}
						},
						error: function(xhr, type, errorThrown) {
							mui.toast("请求失败，请检查登陆状态");
						}
					});
					var text = document.getElementById("start_close").innerHTML;
					//开始扫描
					if(text == "开始扫描") {
						document.getElementById("start_close").innerText = "结束扫描";
						document.getElementById("storage_goodsAddr").disabled = "disabled";
						document.getElementById("start_close").style.color = "#CF2D28";
						document.getElementById("complete_inventory").style.display = "none";
					}
					//结束扫描
					else if(text == "结束扫描") {
						document.getElementById("start_close").innerText = "开始扫描";
						document.getElementById("start_close").style.color = "#2AC845";
						document.getElementById("storage_goodsAddr").disabled = "";
						document.getElementById("complete_inventory").style.display = "block";
						document.getElementById("select_store").style.display = "none";
					} else {; //出错
					}
				});
			}
			//继续扫描
			function again() {
				document.getElementById("again").addEventListener("click", function() {
					mui.toast("继续扫描");
					document.getElementById("start_close").innerText = "结束扫描";
					document.getElementById("storage_goodsAddr").disabled = "disabled";
					document.getElementById("start_close").style.color = "#CF2D28";
					document.getElementById("complete_inventory").style.display = "none";
					//隐藏修改框
					document.getElementById("complete_inventory").style.display = "none";
					//显示盘点框
					document.getElementById("select_store").style.display = "block";
				});
			}
			//完成扫描
			function complete_but() {
				document.getElementById("complete").addEventListener("tap", function(e) {
					e.detail.gesture.preventDefault();
					var btnArray = ['否', '是'];
					mui.confirm("确认完成扫描？", "提示", btnArray, function(e) {
						if(e.index == 1) {
							window.location = "startinventory.html";
						} else {; //否
						}
					})
				})
			}

			//手动盘点
			function handelinventory() {
				var storeName = mui("#storage_goodsAddr")[0].value;
				var assetNum = mui("#handel_assetNum")[0].value;
				var Ifstart = document.getElementById("start_close").innerHTML;
				var Android_URL = IP + '/ias/AndroidInputAsset/InventoryProcess';
				if(Ifstart == "开始扫描") {
					mui.alert("请在开始盘点之后进行手动盘点")
				} else if(Ifstart == "结束扫描") {
					if(assetNum == "") {
						mui.alert("请输入资产编号");
					} else {
						mui.ajax(Android_URL, {
							data: {
								assetNum: assetNum,
								storeName: storeName
							},
							type: 'post',
							dataType: 'json',
							headers: {
								'Content-Type': 'application/json'
							},
							success: function(response) {
								/*获取后台数据*/
								var asset = response.data;
								if(asset.assetNum != null) {
									var assetNum = asset.assetNum; //资产编号
									var assetName = asset.assetName; //资产名称
									var inventoryStore = asset.inventoryStore; //存放地
									var inventoryDepart = asset.inventoryDepart; //部门
									var inventoryBatch = asset.inventoryBatch; //批次号
									var inventoryDate = asset.inventoryDate; //盘点时间
									var inventoryStatus = asset.inventoryStatus; //盘点状态
									var inventoryspanAdrr = asset.inventoryspanAdrr; //扫描地
									/*是否已存在信息框*/
									var msg_div = document.getElementById(assetNum);
									if(msg_div == null) {
										/*动态添加信息框*/
										var parent = document.getElementById("inventory_main");
										var m_li = document.createElement('li');
										m_li.className = "mui-table-view-cell";
										var m_table = document.createElement('div');
										m_table.className = "mui-table";
										//console.log("资产编号："+assetNum);
										/*// 复选框
										var m_l_table_cell = document.createElement('div');
										m_l_table_cell.classList.add('mui-table-cell', 'mui-checkbox', 'mui-col-xs-2', 'mui-left');
										var m_l_input_check = document.createElement('input');
										m_l_input_check.name = "checkbox";
										m_l_input_check.type = "checkbox";
										m_l_input_check.value = assetNum;
										m_l_table_cell.appendChild(m_l_input_check);*/

										// 中间内容
										var m_c_table_cell = document.createElement('div');
										m_c_table_cell.classList.add('mui-table-cell', 'mui-col-xs-10');
										// 中间内容 1
										var m_c_row_1 = document.createElement('div');
										m_c_row_1.className = "mui-row";
										var m_c_asset_name = document.createElement('h4');
										m_c_asset_name.className = "mui-ellipsis";
										//m_c_asset_name.innerText = "资产名称:";
										var m_c_asset_span = document.createElement('span');
										m_c_asset_span.innerText = assetName;
										m_c_asset_name.appendChild(m_c_asset_span);
										m_c_row_1.appendChild(m_c_asset_name);
										// 中间内容2
										var m_c_row_2 = document.createElement('div');
										m_c_row_2.className = "mui-row";
										var m_c_row_2_col_1 = document.createElement('div');
										m_c_row_2_col_1.className = "mui-col-xs-8";
										var m_c_asset_id = document.createElement('h5');
										m_c_asset_id.className = "mui-ellipsis";
										m_c_asset_id.innerText = "资产编号";
										var m_c_asset_id_span = document.createElement('span');
										m_c_asset_id_span.innerText = assetNum;
										m_c_asset_id.appendChild(m_c_asset_id_span);
										m_c_row_2_col_1.appendChild(m_c_asset_id);
										var m_c_row_2_col_2 = document.createElement('div');
										m_c_row_2_col_2.className = "mui-col-xs-4";
										var m_c_asset_status = document.createElement('h5');
										m_c_asset_status.classList.add('mui-ellipsis', 'm-status');
										m_c_asset_status.innerText = inventoryStatus;
										m_c_row_2_col_2.appendChild(m_c_asset_status);
										m_c_row_2.appendChild(m_c_row_2_col_1);
										m_c_row_2.appendChild(m_c_row_2_col_2);

										//中间内容3
										var m_c_row_3 = document.createElement('div');
										m_c_row_3.className = "mui-row";
										var m_c_row_3_col_1 = document.createElement('div');
										m_c_row_3_col_1.className = "mui-col-xs-6";
										var m_c_asset_store = document.createElement('p');
										m_c_asset_store.className = "mui-ellipsis";
										m_c_asset_store.innerText = "存放地：";
										var m_c_asset_store_span = document.createElement('span');
										m_c_asset_store_span.innerText = inventoryStore;
										m_c_asset_store.appendChild(m_c_asset_store_span);
										m_c_row_3_col_1.appendChild(m_c_asset_store);
										var m_c_row_3_col_2 = document.createElement('div');
										m_c_row_3_col_2.className = "mui-col-xs-6";
										var m_c_asset_spanaddr = document.createElement('p');
										m_c_asset_spanaddr.className = "mui-ellipsis";
										m_c_asset_spanaddr.innerText = "扫描地：";
										var m_c_asset_spanadder_span = document.createElement('span');
										m_c_asset_spanadder_span.innerText = inventoryspanAdrr;
										m_c_asset_spanaddr.appendChild(m_c_asset_spanadder_span);
										m_c_row_3_col_2.appendChild(m_c_asset_spanaddr);
										m_c_row_3.appendChild(m_c_row_3_col_1);
										m_c_row_3.appendChild(m_c_row_3_col_2);

										//中间内容4
										var m_c_row_4 = document.createElement('div');
										m_c_row_4.className = "mui-row";
										var m_c_time = document.createElement('span');
										m_c_time.className = "mui-h5";
										m_c_time.innerText = inventoryDate;
										m_c_row_4.appendChild(m_c_time);
										m_c_table_cell.appendChild(m_c_row_1);
										m_c_table_cell.appendChild(m_c_row_2);
										m_c_table_cell.appendChild(m_c_row_3);
										m_c_table_cell.appendChild(m_c_row_4);
										// 右边详情
										var m_r_table_cell = document.createElement('div');
										m_r_table_cell.classList.add('mui-table-cell', 'mui-text-right', 'mui-col-xs-2', 'm-numbers-href');
										m_r_table_cell.title = assetName;
										m_r_table_cell.id = assetNum;

										var m_r_icon = document.createElement('a');
										m_r_icon.className = "mui-navigate-right";
										m_r_table_cell.appendChild(m_r_icon);

										//m_table.appendChild(m_l_table_cell);
										m_table.appendChild(m_c_table_cell);
										m_table.appendChild(m_r_table_cell);
										m_li.appendChild(m_table);
										/*parent.appendChild(m_li);*/
										parent.insertBefore(m_li,parent.firstElementChild);
										mui.toast("手动盘点成功");
										tap_sub_event();
									} else {
										mui.toast("已盘点");
									}
								} else {
									mui.toast("不存在此资产");
								}
							},
							error: function(xhr, textStatus, errorThrown) {
								mui.toast("数据错误，请检查登陆状态");
							}
						});
					}
				} else {
					mui.toast("信息错误");
				}
			}
			//主页返回键处理
			mui.back = function() {
				window.location = "main.html";
			}
			//nfc功能
			var NfcAdapter;
			// 密钥
			var key_A = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00];

			function listenNFCStatus() {
				try {
					var main = plus.android.runtimeMainActivity();
					// 加载安卓sdk中用于启动活动的Intent;这是想要要执行操作抽象描述的数据结构
					var Intent = plus.android.importClass('android.content.Intent');
					// 创建窗口
					var Activity = plus.android.importClass('android.app.Activity');
					// 描述目标操作和意图
					var PendingIntent = plus.android.importClass('android.app.PendingIntent');
					// 过滤器
					var IntentFilter = plus.android.importClass('android.content.IntentFilter');
					// 适配器
					NfcAdapter = plus.android.importClass('android.nfc.NfcAdapter');
					// 获取手机默认的适配器
					var nfcAdapter = NfcAdapter.getDefaultAdapter(main);
					if(nfcAdapter == null) {
						mui.toast("设备不支持NFC！");
						return;
					}
					if(!nfcAdapter.isEnabled()) {
						alert("请在系统设置中先启用NFC功能！");
						return;
					}
					// 创建意图对象
					var intent = new Intent(main, main.getClass());
					// 为意图添加附加标志  该活动以运行则不启动该活动
					intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
					// 检索并启动新活动
					var pendingIntent = PendingIntent.getActivity(main, 0, intent, 0);
					// 为活动匹配一个过滤器
					var ndef = new IntentFilter("android.nfc.action.TECH_DISCOVERED");
					ndef.addDataType("*/*");
					var intentFiltersArray = [ndef];
					// 所有支持的标签技术
					var techListsArray = [
						["android.nfc.tech.IsoDep"],
						["android.nfc.tech.NfcA"],
						["android.nfc.tech.NfcB"],
						["android.nfc.tech.NfcF"],
						["android.nfc.tech.Nfcf"],
						["android.nfc.tech.NfcV"],
						["android.nfc.tech.NdefFormatable"],
						["android.nfc.tech.MifareClassic"],
						["android.nfc.tech.MifareUltralight"]
					];
					// 监听获取intent总信息
					document.addEventListener("newintent",
						function() {
							console.error('newintent');
							setTimeout(handle_nfc_data1, 1000);
						}, false);
					document.addEventListener("pause", function(e) {
						if(nfcAdapter) {
							// 禁用对给定活动的前台分派
							nfcAdapter.disableForegroundDispatch(main);
							console.log('pause');
						}
					}, false);
					document.addEventListener("resume", function(e) {
						if(nfcAdapter) {
							console.log('resume');
							// 启用对给定活动的前台分派 参数1.要调度的活动 2.等待开始发送的意图3.过滤器4.所能匹配的标签类型列表
							nfcAdapter.enableForegroundDispatch(main, pendingIntent, intentFiltersArray, techListsArray);
						}
					}, false);
					nfcAdapter.enableForegroundDispatch(main, pendingIntent, intentFiltersArray, techListsArray);
				} catch(e) {
					console.error(e);
				}
			}

			function handle_nfc_data1() {
				// 获取主应用
				var main = plus.android.runtimeMainActivity();
				// 获取正在请求的intent
				var intent = main.getIntent();
				console.log("action type:" + intent.getAction());
				if("android.nfc.action.TECH_DISCOVERED" == intent.getAction()) {
					if(readyWriteData) {
						__write(intent);
						readyWriteData = false;
					} else if(readyRead) {

						__read(intent);
					}
				} else {
					console.log("action 失败");
				}
			}

			function readData() {
				readyRead = true;
			}

			function closereadData() {
				readyRead = false;
			}

			// 从nfc标签中读取的数据
			var readDataResult = "";
			var a = "";

			function __read(intent) {
				// 判断密钥是否正确
				var isAuth = false;
				try {
					var content = "";
					//waiting.setTitle('请勿移开标签\n正在读取数据...');
					plus.android.importClass("android.nfc.Tag");
					var MifareClassic = plus.android.importClass("android.nfc.tech.MifareClassic");
					var tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
					var tagID = tag.getId();
					console.log("Tag的ID为：" + bytesToHexString(tagID));
					// 实例化一个MifareClassic对象
					var mfc = MifareClassic.get(tag);
					if(mfc != null) {
						try {
							mfc.connect();
							// 获取扇区数量
							var nSecont = mfc.getSectorCount();
							//只读取第一个扇区的1号块中数据
							isAuth = mfc.authenticateSectorWithKeyA(0, key_A);
							if(isAuth) {
								var nBlock = mfc.getBlockCountInSector(0);
								var data = mfc.readBlock(1);
								console.log(data);
								var result = bytesToHexString(data);

								//var a="";
								//console.log("2");
								//**转为16进制*/
								//								mui.ajax(IP+'/ias/PCHanderTag/handleReadData',{
								//									data:{datastr :result},
								//									type: 'post',
								//									dataType: 'json',
								//									headers:{'Content-Type':'application/json'},
								//									success: function(response) {
								//										console.log("成功");
								//										//a=response.data;
								//										console.log(response);
								//									},
								//									error: function(xhr, textStatus, errorThrown) {
								//										mui.toast("数据错误，请检查登陆状态");
								//									}
								//								})

								//mui.alert(a);
								//content = readDataResult;
								readDataResult = result;

								if(readDataResult != null) {
									var truedata = "";
									var data = {
										datastr: result
									}
									mui.ajax(IP + '/ias/PCHanderTag/handleReadData', {
										data: data,
										type: 'post',
										dataType: 'json',
										//headers:{'Content-Type':'application/json'},
										success: function(response) {
											truedata = response.data;
											console.log(response.data);
										},
										error: function(xhr, textStatus, errorThrown) {
											mui.alert("数据错误，请检查登陆状态");
										}
									})
									console.log(truedata);
									var assetNum = truedata;
									var storeName = mui("#storage_goodsAddr")[0].value;
									var text = document.getElementById("start_close").innerHTML;
									if(text == "结束扫描") {
										mui.ajax(IP + '/ias/AndroidInputAsset/InventoryProcess', {
											data: {
												assetNum: assetNum,
												storeName: storeName
											},
											type: 'post',
											dataType: 'json',
											headers: {
												'Content-Type': 'application/json'
											},
											success: function(response) {
												/*获取后台数据*/
												var asset = response.data;
												if(asset.assetNum != null) {
													var assetNum = asset.assetNum; //资产编号
													var assetName = asset.assetName; //资产名称
													var inventoryStore = asset.inventoryStore; //存放地
													var inventoryDepart = asset.inventoryDepart; //部门
													var inventoryBatch = asset.inventoryBatch; //批次号
													var inventoryDate = asset.inventoryDate; //盘点时间
													var inventoryStatus = asset.inventoryStatus; //盘点状态
													var inventoryspanAdrr = asset.inventoryspanAdrr; //扫描地
													/*是否已存在信息框*/
													var msg_div = document.getElementById(assetNum);
													if(msg_div == null) {
														/*动态添加信息框*/
														var parent = document.getElementById("inventory_main");
														var m_li = document.createElement('li');
														m_li.className = "mui-table-view-cell";
														var m_table = document.createElement('div');
														m_table.className = "mui-table";
														//console.log("资产编号："+assetNum);
														// 复选框
														var m_l_table_cell = document.createElement('div');
														m_l_table_cell.classList.add('mui-table-cell', 'mui-checkbox', 'mui-col-xs-2', 'mui-left');
														var m_l_input_check = document.createElement('input');
														m_l_input_check.name = "checkbox";
														m_l_input_check.type = "checkbox";
														m_l_input_check.value = assetNum;
														m_l_table_cell.appendChild(m_l_input_check);

														// 中间内容
														var m_c_table_cell = document.createElement('div');
														m_c_table_cell.classList.add('mui-table-cell', 'mui-col-xs-8');
														// 中间内容 1
														var m_c_row_1 = document.createElement('div');
														m_c_row_1.className = "mui-row";
														var m_c_asset_name = document.createElement('h4');
														m_c_asset_name.className = "mui-ellipsis";
														//m_c_asset_name.innerText = "资产名称:";
														var m_c_asset_span = document.createElement('span');
														m_c_asset_span.innerText = assetName;
														m_c_asset_name.appendChild(m_c_asset_span);
														m_c_row_1.appendChild(m_c_asset_name);
														// 中间内容2
														var m_c_row_2 = document.createElement('div');
														m_c_row_2.className = "mui-row";
														var m_c_row_2_col_1 = document.createElement('div');
														m_c_row_2_col_1.className = "mui-col-xs-8";
														var m_c_asset_id = document.createElement('h5');
														m_c_asset_id.className = "mui-ellipsis";
														m_c_asset_id.innerText = "资产编号";
														var m_c_asset_id_span = document.createElement('span');
														m_c_asset_id_span.innerText = assetNum;
														m_c_asset_id.appendChild(m_c_asset_id_span);
														m_c_row_2_col_1.appendChild(m_c_asset_id);
														var m_c_row_2_col_2 = document.createElement('div');
														m_c_row_2_col_2.className = "mui-col-xs-4";
														var m_c_asset_status = document.createElement('h5');
														m_c_asset_status.classList.add('mui-ellipsis', 'm-status');
														m_c_asset_status.innerText = inventoryStatus;
														m_c_row_2_col_2.appendChild(m_c_asset_status);
														m_c_row_2.appendChild(m_c_row_2_col_1);
														m_c_row_2.appendChild(m_c_row_2_col_2);

														//中间内容3
														var m_c_row_3 = document.createElement('div');
														m_c_row_3.className = "mui-row";
														var m_c_row_3_col_1 = document.createElement('div');
														m_c_row_3_col_1.className = "mui-col-xs-6";
														var m_c_asset_store = document.createElement('p');
														m_c_asset_store.className = "mui-ellipsis";
														m_c_asset_store.innerText = "存放地：";
														var m_c_asset_store_span = document.createElement('span');
														m_c_asset_store_span.innerText = inventoryStore;
														m_c_asset_store.appendChild(m_c_asset_store_span);
														m_c_row_3_col_1.appendChild(m_c_asset_store);
														var m_c_row_3_col_2 = document.createElement('div');
														m_c_row_3_col_2.className = "mui-col-xs-6";
														var m_c_asset_spanaddr = document.createElement('p');
														m_c_asset_spanaddr.className = "mui-ellipsis";
														m_c_asset_spanaddr.innerText = "扫描地：";
														var m_c_asset_spanadder_span = document.createElement('span');
														m_c_asset_spanadder_span.innerText = inventoryspanAdrr;
														m_c_asset_spanaddr.appendChild(m_c_asset_spanadder_span);
														m_c_row_3_col_2.appendChild(m_c_asset_spanaddr);
														m_c_row_3.appendChild(m_c_row_3_col_1);
														m_c_row_3.appendChild(m_c_row_3_col_2);

														//中间内容4
														var m_c_row_4 = document.createElement('div');
														m_c_row_4.className = "mui-row";
														var m_c_time = document.createElement('span');
														m_c_time.className = "mui-h5";
														m_c_time.innerText = inventoryDate;
														m_c_row_4.appendChild(m_c_time);
														m_c_table_cell.appendChild(m_c_row_1);
														m_c_table_cell.appendChild(m_c_row_2);
														m_c_table_cell.appendChild(m_c_row_3);
														m_c_table_cell.appendChild(m_c_row_4);
														// 右边详情
														var m_r_table_cell = document.createElement('div');
														m_r_table_cell.classList.add('mui-table-cell', 'mui-text-right', 'mui-col-xs-2', 'm-numbers-href');
														m_r_table_cell.title = assetName;
														m_r_table_cell.id = assetNum;

														var m_r_icon = document.createElement('a');
														m_r_icon.className = "mui-navigate-right";
														m_r_table_cell.appendChild(m_r_icon);

														m_table.appendChild(m_l_table_cell);
														m_table.appendChild(m_c_table_cell);
														m_table.appendChild(m_r_table_cell);
														m_li.appendChild(m_table);
														parent.appendChild(m_li);
														mui.toast("手动盘点成功");
														tap_sub_event();
													} else {
														mui.toast("已盘点");
													}
												} else {
													mui.toast("不存在此资产");
												}
											},
											error: function(xhr, textStatus, errorThrown) {
												mui.toast("数据错误，请检查登陆状态");
											}
										});
									} else {
										closereadData();
									}
								} else {
									mui.toast("扫描失败");
								}
								//console.log(result);
								console.log(readDataResult);
							}
						} catch(e) {
							mui.toast("读取失败，请重新扫描");
							mfc.close();
						}
						mfc.close();
					} else {
						console.log("skySeraph, your Tag is not MifareClassic");
					}
				} catch(e) {
					alert(e);
				}
				return readDataResult;
			}

			function stringToHex(str) {　　　　
				var val = "";　　　　
				for(var i = 0; i < str.length; i++) {
					if(val == "")　　　　　　　　
						val = str.charCodeAt(i).toString(16);　　　　　　
					else　　　　　　　　
						val += "," + str.charCodeAt(i).toString(16);　　　　
				}　　　　
				return val;　　
			}

			function bytesToHexString(inarray) {
				var i, j, x;
				var hex = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
					"B", "C", "D", "E", "F"
				];
				var out = "";
				for(j = 0; j < inarray.length; ++j) {
					x = parseInt(inarray[j]) & 0xff;
					i = (x >> 4) & 0x0f;
					out += hex[i];
					i = x & 0x0f;
					out += hex[i];
				}
				var value = "";
				var outresult = "";
				for(var k = 0; k < out.length; k++) {
					if(out.charAt(k) != '0') {
						value = out.substr(k, out.length);
						outresult += value;
						break;
					}
				}
				return outresult;
			}
			// 在初始化plus api后在调用
			document.addEventListener('plusready', listenNFCStatus, false);

			var waiting;
			var readyWriteData = false;
			var readyRead = false;

			function writeData() {
				var textEle = document.getElementById('text');

				if(!textEle.value) {
					alert('请输入要写入的内容');
					return;
				}
				readyWriteData = true;
				waiting = plus.nativeUI.showWaiting("请将NFC标签靠近！");
			}
		</script>

	</head>

	<body>

		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">盘点资产</h1>
		</header>
		<!-- <div class="startinventory_backimg"> -->
		<!--选择存放地、开始盘点-->
		<div class="mui-content">
			<div id="select_store">
				<select id="storage_goodsAddr" class="mui-h5"></select>
				<button id="start_close" onclick="readData()">开始扫描</button>
				<a id="handleinventory" href="#popover">手动盘点</a>
			</div>
		</div>

		<!--结束盘点-->
		<div id="complete_inventory" class="content">
			<button id="complete">完成扫描</button>
			<button id="again">继续扫描</button>
		</div>
		<!-- </div> -->
		<!--手动盘点-->
		<div id="popover" class="mui-popover">
			<div class="handel_inventory">
				<br/>
				<span style="float: left;">资产编号:</span>
				<input type="text" name="handel_assetNum" id="handel_assetNum" placeholder="手动盘点资产编号">
				<button type="button" class="mui-btn mui-btn-blue" onclick="handelinventory()">手动盘点</button>
			</div>
		</div>
		<!--结束手动盘点-->

		<!--盘点信息-->
		<div class="mui-content">
			<ul class="mui-table-view mui-table-view-striped mui-table-view-condensed" id="inventory_main">
			</ul>
		</div>

	</body>

</html>
<script type="text/javascript">
	mui.plusReady(function() {
		/*监听手机的返回键*/
		if('Android' == plus.os.name) {
			var first = null;
			mui.back = function() {
				if(!first) {
					first = new Date().getTime();
					mui.toast('再按一次退出应用');
					setTimeout(function() {
						first = null;
					}, 1000);
				} else {
					if(new Date().getTime() - first < 1000) {
						plus.runtime.quit();
					}
				}
			}
		}
	})
</script>